package demo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class MyThreadPool{
    private BlockingQueue<Runnable> blockingQueue=new LinkedBlockingQueue<>();
    static class Worker extends Thread{
        private BlockingQueue<Runnable> blockingQueue=new LinkedBlockingQueue<>();
        public Worker(BlockingQueue<Runnable> blockingQueue){
            this.blockingQueue=blockingQueue;
        }

        @Override
        public void run() {
            while (true){
                try {
                    Runnable task=blockingQueue.take();
                    task.run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    private List<Worker> workerList=new ArrayList<>();
    public MyThreadPool(int n){
        for(int i=0;i<n;i++){
            Worker worker=new Worker(blockingQueue);
            worker.start();
            workerList.add(worker);
        }
    }

    public void submit(Runnable runnable){
        try {
            blockingQueue.put(runnable);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
public class Demo2 {
}
